package com.hxkj.service.impl;

import com.hxkj.dao.ContentMappingDao;
import com.hxkj.domain.enums.ColumnExceptionEnum;
import com.hxkj.domain.po.ContentMapping;
import com.hxkj.service.ContentMappingService;
import com.platform.common.domain.exception.CustomException;
import com.platform.common.domain.exception.CustomMessageException;
import com.platform.common.domain.result.ResultDataStruct;
import com.platform.common.domain.result.ResultMessageStruct;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName ContentMappingServiceImpl
 * @Description TODO
 * @Author Mr.zheng
 * @Date 2018/9/9 14:43
 * @Version 1.0
 */
@Service
@Slf4j
public class ContentMappingServiceImpl implements ContentMappingService {

    @Autowired
    private ContentMappingDao contentMappingDao;

    @Override
    public ResultDataStruct<List<ContentMapping>> getContentMappingList(ContentMapping contentMapping) throws Exception {
        ResultDataStruct<List<ContentMapping>> resultDataStruct = new ResultDataStruct<>();
        try {
            List<ContentMapping> contentMappingList = contentMappingDao.getContentMappingList(contentMapping);
            if (contentMappingList != null && contentMappingList.size() > 0) {
                resultDataStruct.setData(contentMappingList);
                resultDataStruct.setCode(200);
                return resultDataStruct;
            }
            resultDataStruct.setCode(401);
            resultDataStruct.setMessage("没有获取到映射字段");
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
        return resultDataStruct;
    }

    @Override
    public ResultMessageStruct saveContentMapping(ContentMapping contentMapping) throws Exception {
        ResultMessageStruct resultMessageStruct = new ResultMessageStruct();
        try {
            int i = contentMappingDao.saveContentMapping(contentMapping);
            if (i == 0) {
                resultMessageStruct.setCode(401);
                resultMessageStruct.setMessage("映射字段添加失败");
                return resultMessageStruct;
            }
            resultMessageStruct.setCode(200);
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
        return resultMessageStruct;
    }

    @Override
    public ResultDataStruct<List<String>> getContentNameList() throws Exception {
        List<String> list = contentMappingDao.getContentNameList();
        ResultDataStruct<List<String>> resultDataStruct = new ResultDataStruct<>();
        resultDataStruct.setData(list);
        return resultDataStruct;
    }
}
